package xyz.jcat.sco.admin.oauth2.server.auth;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import xyz.jcat.sco.common.LoginUser;

import java.util.Arrays;
import java.util.HashSet;

@Slf4j
@Component
public class UserDetailsServiceImpl implements UserDetailsService {

    //TODO 系统用户登录
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LoginUser loginUser = new LoginUser();
        loginUser.setAccountNonExpired(true);
        loginUser.setAccountNonLocked(true);
        loginUser.setCredentialsNonExpired(true);
        loginUser.setEnabled(true);
        loginUser.setUserId(1L);
        loginUser.setUsername(username);
        loginUser.setPassword("$2a$10$j.exEd8XQ6ZWi9ItAI9oMONryXvyA9n0lYv6O7SvUoKrK7D0O/xKe");
        loginUser.setRoleIds(new HashSet<>(Arrays.asList(1L, 2L)));
        return new UserDetailsImpl(loginUser);
    }
}
